import numpy as np


class LowPassFilter:
    def __init__(self) -> None:
        super().__init__()

        self.alpha = 0.0
        self.dataOld = 0.0
        self.isIni = False

    def setPara(self, fc: float, ts: float):
        self.alpha = ts / (ts + 1.0 / (2 * np.pi * fc))

    def ftOut(self, data: float):
        res = 0.0
        if self.isIni:
            res = (1 - self.alpha) * self.dataOld + self.alpha * data
        else:
            res = data
            self.isIni = True
        self.dataOld = res
        return res
